package com.blog.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import com.blog.entity.PageResult;
import com.blog.mapper.BlogTypeMapper;
import com.blog.pojo.BlogType;
import com.blog.service.BlogTypeService;

@Service
public class BlogTypeServiceImpl implements BlogTypeService {

	@Autowired
	private BlogTypeMapper blogTypeMapper;

	@Autowired
	private RedisTemplate redisTemplate;

	public List<BlogType> getTypeList() {
		// 从缓存中取数据
		List<BlogType> list = (List<BlogType>) redisTemplate.boundValueOps("blogTypeList").get();
		// 如果缓存为空
		if (list == null) {
			List<BlogType> blogTypeList = blogTypeMapper.getTypeList();
			//存入缓存
			redisTemplate.boundValueOps("blogTypeList").set(blogTypeList);
			return blogTypeList;
		}
		return list;
	}

	public BlogType getBlogTypeByTypeId(int typeId) {
		// TODO Auto-generated method stub
		return blogTypeMapper.getBlogTypeByTypeId(typeId);
	}

}
